package com.hua.ma.sang.gulimall.common.entity;

import com.huaxiaofan.developer.aop.aspect.Entity.Response;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

/**
 * @author huaxiaofan
 * @date 2022/5/11 2:01 下午
 */
public class Results {

   public static final String REQUEST_SUCCESS = "request_success";
   public static final String INTERNAL_SERVER_ERROR = "internal_server_error";

   private static final ResponseEntity OK;
   private static final ResponseEntity NO_CONTENT;
   private static final ResponseEntity ERROR;

   private Results() {
   }

   /**
    * 使用静态代码块初始化常量值
    */
   static {
      OK = new ResponseEntity(HttpStatus.OK);
      NO_CONTENT = new ResponseEntity(HttpStatus.NO_CONTENT);
      ERROR = new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
   }

   public static <T> ResponseEntity<T> ok() {
      return OK;
   }

   public static ResponseEntity<Response> success() {
      Response response = new Response(REQUEST_SUCCESS, "", true);
      return ResponseEntity.ok(response);
   }

   public static <T> ResponseEntity<DataResponse<T>> success(T data) {
      DataResponse<T> response = new DataResponse<T>(REQUEST_SUCCESS, "", true, data);
      return  ResponseEntity.ok(response);
   }

}
